<template>
  <div :id="id" style="width: 50%; height: 400px"></div>
</template>

<script>
import * as echarts from 'echarts'
export default {
  props: {
    id: {
      type: String,
      default: 'pie1'
    },
    data: {
      type: Array,
      required: true
    }
  },
  mounted() {
    var chartDom = document.getElementById(this.id)
    var myChart = echarts.init(chartDom)
    var option

    option = {
      title: {
        text: '注册会员性别分布情况',
        x: 'center'
      },
      tooltip: {
        trigger: 'item'
      },
      legend: {
        top: '5%',
        left: 'center'
      },
      series: [
        {
          name: '性别分布:',
          type: 'pie',
          radius: ['40%', '70%'],
          avoidLabelOverlap: false,
          itemStyle: {
            borderRadius: 10,
            borderColor: '#fff',
            borderWidth: 2,
            normal: {
              color: function (colors) {
                var colorList = ['#ffff00', '#ff0000', '#00ff00']
                return colorList[colors.dataIndex]
              }
            }
          },
          label: {
            show: false,
            position: 'center'
          },
          emphasis: {
            label: {
              show: true,
              fontSize: '40',
              fontWeight: 'bold'
            }
          },
          labelLine: {
            show: false
          },
          data: this.data
          //   data: [
          //     { value: 1048, name: 'Search Engine' },
          //     { value: 735, name: 'Direct' },
          //     { value: 580, name: 'Email' },
          //     { value: 484, name: 'Union Ads' },
          //     { value: 300, name: 'Video Ads' }
          //   ]
        }
      ]
    }

    option && myChart.setOption(option)
  }
}
</script>

<style lang="scss" scoped>
</style>